package com.netease.pris.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.provider.SearchRecentSuggestions;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AutoCompleteTextView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.netease.framework.ActivityEx;
import com.netease.pris.activity.a.ad;
import com.netease.pris.atom.u;
import com.netease.pris.v;
import java.util.LinkedList;
import java.util.Stack;

public class SearchActivity extends ActivityEx
{
  public static final int a = 0;
  public static final int b = 1;
  public static final String c = "extra_query";
  public static final String d = "extra_link";
  private AutoCompleteTextView A;
  private ImageView B;
  private ImageView C;
  private InputMethodManager D;
  private TextWatcher E = new gb(this);
  private AdapterView.OnItemClickListener F = new fz(this);
  View.OnClickListener e = new ga(this);
  AbsListView.OnScrollListener f = new fy(this);
  com.netease.pris.b g = new fx(this);
  private boolean h = false;
  private String i = null;
  private int j = 0;
  private int k;
  private String l = "/source/search.atom?page=1&len=10&query={searchTerms}";
  private String m = null;
  private String n = null;
  private Stack o = null;
  private LinkedList p;
  private Context q = null;
  private TextView r = null;
  private ListView s = null;
  private ImageView t = null;
  private BaseAdapter u = null;
  private ProgressBar v = null;
  private View w;
  private LinearLayout x = null;
  private ProgressBar y = null;
  private TextView z = null;

  private void a(int paramInt, u paramu, String paramString1, String paramString2)
  {
    switch (paramInt)
    {
    default:
      return;
    case 1100:
      this.j = v.a().d(paramString1, paramString2, com.netease.pris.atom.b.a);
    case 1105:
    case 304:
    case 302:
    case 303:
    }
    while (true)
    {
      this.p.add(new Integer(this.j));
      break;
      this.j = v.a().e(paramString1, paramString2, com.netease.pris.atom.b.a);
      continue;
      this.j = v.a().a(paramString1);
      continue;
      this.j = v.a().a(paramu);
      continue;
      this.j = v.a().b(paramu);
    }
  }

  private void a(Intent paramIntent)
  {
    String str;
    AutoCompleteTextView localAutoCompleteTextView;
    if ("android.intent.action.SEARCH".equals(paramIntent.getAction()))
    {
      str = paramIntent.getStringExtra("query");
      this.l = paramIntent.getStringExtra("extra_link");
      a(str);
      this.A.setText(str);
      localAutoCompleteTextView = this.A;
      if (str != null)
        break label61;
    }
    label61: for (int i1 = 0; ; i1 = str.length())
    {
      localAutoCompleteTextView.setSelection(i1);
      return;
    }
  }

  private void a(com.netease.pris.protocol.d paramd, boolean paramBoolean)
  {
    if ((paramd == null) || (paramd.h == null));
    while (true)
    {
      return;
      if ((this.u != null) && ((this.u instanceof ad)))
      {
        if (paramBoolean)
        {
          ((ad)this.u).a(paramd.h);
          continue;
        }
        ((ad)this.u).c();
        ((ad)this.u).a();
        ((ad)this.u).b(paramd.h);
        continue;
      }
    }
  }

  private void a(String paramString)
  {
    this.m = paramString;
    new SearchRecentSuggestions(this, "com.netease.pris.provider.SearchSuggestionProvider", 1).saveRecentQuery(paramString, null);
    if ((paramString != null) && (paramString.length() > 200))
      paramString = paramString.substring(0, 200);
    a(1100, null, this.l, paramString);
    c_();
  }

  private void b(boolean paramBoolean)
  {
    if ((this.x == null) || (this.y == null) || (this.z == null));
    while (true)
    {
      return;
      if (paramBoolean)
      {
        this.x.setVisibility(0);
        this.y.setVisibility(0);
        this.z.setText(2131361949);
        continue;
      }
      this.x.setVisibility(8);
    }
  }

  private void c()
  {
    this.t = ((ImageView)findViewById(2131558408));
    this.r = ((TextView)findViewById(2131558508));
    this.s = ((ListView)findViewById(2131558597));
    this.v = ((ProgressBar)findViewById(2131558412));
    this.w = LayoutInflater.from(this).inflate(2130903048, null);
    this.s.setDivider(null);
    this.s.setDividerHeight(0);
    this.s.addFooterView(this.w);
    this.x = ((LinearLayout)this.w.findViewById(2131558426));
    this.y = ((ProgressBar)this.w.findViewById(2131558427));
    this.z = ((TextView)this.w.findViewById(2131558428));
    this.A = ((AutoCompleteTextView)findViewById(2131558514));
    this.B = ((ImageView)findViewById(2131558515));
    this.C = ((ImageView)findViewById(2131558516));
  }

  private void e()
  {
    String[] arrayOfString = new String[7];
    arrayOfString[0] = "icon";
    arrayOfString[1] = "mark";
    arrayOfString[2] = "title";
    arrayOfString[3] = "content";
    arrayOfString[4] = "ratingbar";
    arrayOfString[5] = "button";
    arrayOfString[6] = "subs";
    int[] arrayOfInt = new int[7];
    arrayOfInt[0] = 2131558436;
    arrayOfInt[1] = 2131558522;
    arrayOfInt[2] = 2131558424;
    arrayOfInt[3] = 2131558525;
    arrayOfInt[4] = 2131558551;
    arrayOfInt[5] = 2131558526;
    arrayOfInt[6] = 2131558553;
    ad localad = new ad(this, 2, 2130903087, arrayOfString, arrayOfInt);
    if (localad != null)
    {
      if (this.s != null)
        this.s.setAdapter(localad);
      localad.e(this.k);
      this.u = localad;
    }
  }

  private void f()
  {
    if (this.t != null)
      this.t.setOnClickListener(this.e);
    if (this.s != null)
    {
      this.s.setOnItemClickListener(this.F);
      this.s.setOnScrollListener(this.f);
    }
    if (this.u != null)
      ((ad)this.u).a(this.e);
    this.A.addTextChangedListener(this.E);
    this.A.setHint(2131361913);
    this.B.setOnClickListener(this.e);
    this.C.setOnClickListener(this.e);
    this.C.setClickable(false);
    this.C.setEnabled(false);
  }

  private void g()
  {
    if (this.i != null)
    {
      this.h = true;
      a(1105, null, this.i, this.m);
      this.s.addFooterView(this.w);
      c_();
      b(true);
    }
  }

  public void b()
  {
    this.t.setVisibility(0);
    this.v.setVisibility(8);
  }

  public void c_()
  {
    this.t.setVisibility(8);
    this.v.setVisibility(0);
  }

  public void finish()
  {
    Intent localIntent = new Intent();
    Bundle localBundle = new Bundle();
    localBundle.putString("extra_query", this.A.getText().toString());
    localIntent.putExtras(localBundle);
    setResult(-1, localIntent);
    super.finish();
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903100);
    this.n = null;
    this.q = this;
    this.D = ((InputMethodManager)getSystemService("input_method"));
    v.a().a(this.g);
    this.o = new Stack();
    this.p = new LinkedList();
    c();
    e();
    f();
    setTitle(2131361908);
    a(getIntent());
    this.k = com.netease.b.a.d.f();
  }

  public boolean onCreateOptionsMenu(Menu paramMenu)
  {
    return true;
  }

  public void onDestroy()
  {
    super.onDestroy();
    v.a().b(this.g);
    com.netease.image.d.a().a(this.k);
    if (this.v != null)
      this.v.setVisibility(8);
    if (this.y != null)
      this.y.setVisibility(8);
    if (this.o != null)
      this.o.clear();
    if (this.p != null)
      this.p.clear();
    if (this.u != null)
    {
      ((ad)this.u).b();
      this.u = null;
    }
    if (this.e != null)
      this.e = null;
    if (this.f != null)
      this.f = null;
    if (this.F != null)
      this.F = null;
    if (this.s != null)
      this.s = null;
    this.i = null;
    this.m = null;
    this.n = null;
    this.r = null;
    this.t = null;
    this.v = null;
    this.w = null;
    this.x = null;
    this.y = null;
    this.z = null;
    this.q = null;
  }

  public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent)
  {
    if (4 != paramInt);
    boolean bool;
    do
    {
      bool = super.onKeyDown(paramInt, paramKeyEvent);
      return bool;
    }
    while (this.o.empty());
    String str = (String)this.o.pop();
    if (str == null);
    while (true)
    {
      this.n = str;
      bool = true;
      break;
      a(304, null, str, null);
    }
  }

  protected void onNewIntent(Intent paramIntent)
  {
    setIntent(paramIntent);
    a(paramIntent);
  }

  public boolean onPrepareOptionsMenu(Menu paramMenu)
  {
    return true;
  }
}

/* Location:           D:\android\hack\dex2jar-0.0.9.8\classes_dex2jar.jar
 * Qualified Name:     com.netease.pris.activity.SearchActivity
 * JD-Core Version:    0.6.0
 */